using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using Yoozoo.UI;
using Yoozoo.UI.YGUI;

public class CanvasBinder : BinderBase
{
    public enum AttributeType : int
    {
        scaleFactor,
        referencePixelsPerUnit,
        overridePixelPerfect,
        pixelPerfect,
        planeDistance,
        overrideSorting,
        sortingOrder,
        targetDisplay,
        sortingLayerID,
        sortingLayerName,
        normalizedSortingGridSize,
        enabled,
    }
    
    private Canvas _target;
    
    public CanvasBinder(UIExpansion owner, LinkerConfig config) : base(owner, config)
    {
    }

    public CanvasBinder()
    {
        
    }

    public override void Init(LinkerConfig config)
    {
        GameObject targetGo = _owner.GetStoredGameObject(config.StoredGameObjectIndex);
        if (targetGo == null)
        {
            return;
        }
        _target = targetGo.GetComponent<Canvas>();
        _active = _target != null;
    }
    public override void SetSingle(float value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.scaleFactor:
                _target.scaleFactor = value;
            break;
            case AttributeType.referencePixelsPerUnit:
                _target.referencePixelsPerUnit = value;
            break;
            case AttributeType.planeDistance:
                _target.planeDistance = value;
            break;
            case AttributeType.normalizedSortingGridSize:
                _target.normalizedSortingGridSize = value;
            break;
            default:
            break;
        }
        base.SetSingle(value);
    }
    
    public override void SetBoolean(bool value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.overridePixelPerfect:
                _target.overridePixelPerfect = value;
            break;
            case AttributeType.pixelPerfect:
                _target.pixelPerfect = value;
            break;
            case AttributeType.overrideSorting:
                _target.overrideSorting = value;
            break;
            case AttributeType.enabled:
                _target.enabled = value;
            break;
            default:
            break;
        }
        base.SetBoolean(value);
    }
    
    public override void SetInt32(int value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.sortingOrder:
                _target.sortingOrder = value;
            break;
            case AttributeType.targetDisplay:
                _target.targetDisplay = value;
            break;
            case AttributeType.sortingLayerID:
                _target.sortingLayerID = value;
            break;
            default:
            break;
        }
        base.SetInt32(value);
    }
    
    public override void SetString(string value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.sortingLayerName:
                _target.sortingLayerName = value;
            break;
            default:
            break;
        }
        base.SetString(value);
    }
    
}